﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Windows.Forms;
using Protocolo;
using Protocolo.Exception;

public partial class anotar_evento : System.Web.UI.Page
{
    private Evento even;
    protected void Page_Load(object sender, EventArgs e)
    {
        String bandera = ClientQueryString;
        string id = bandera.Substring(3);
        try
        {
            even = Control_calendario.busca_unico(id);

            if (even != null)
            {
                HtmlTableRow r = new HtmlTableRow();
                HtmlTableCell b = new HtmlTableCell();
                HtmlTableCell c = new HtmlTableCell();
                b.BgColor = "#a9a9a9";
                c.BgColor = "#E0E9F5";

                b.Controls.Add(new LiteralControl("<b>NOMBRE</b>"));
                c.Controls.Add(new LiteralControl(even.Nombre));
                r.Cells.Add(b);
                r.Cells.Add(c);
                eventos1.Rows.Add(r);
                r = new HtmlTableRow();
                b = new HtmlTableCell();
                c = new HtmlTableCell();
                b.BgColor = "#a9a9a9";
                c.BgColor = "#E0E9F5";

                b.Controls.Add(new LiteralControl("<b>LUGAR</b>"));
                c.Controls.Add(new LiteralControl(even.Lugar));
                r.Cells.Add(b);
                r.Cells.Add(c);
                eventos1.Rows.Add(r);

                r = new HtmlTableRow();
                b = new HtmlTableCell();
                c = new HtmlTableCell();
                b.BgColor = "#a9a9a9";
                c.BgColor = "#E0E9F5";

                string[] fe = even.Fecha.ToString().Split(new char[] {' '});
                b.Controls.Add(new LiteralControl("<b>FECHA</b>"));
                c.Controls.Add(new LiteralControl(fe[0]));
                r.Cells.Add(b);
                r.Cells.Add(c);
                eventos1.Rows.Add(r);

                r = new HtmlTableRow();
                b = new HtmlTableCell();
                c = new HtmlTableCell();
                b.BgColor = "#a9a9a9";
                c.BgColor = "#E0E9F5";
                string[] hora_ini = even.Hora_ini.ToString().Split(new char[] {' '});
                b.Controls.Add(new LiteralControl("<b>HORA INICIO</b>"));
                c.Controls.Add(new LiteralControl(hora_ini[1]));
                r.Cells.Add(b);
                r.Cells.Add(c);
                eventos1.Rows.Add(r);
                r = new HtmlTableRow();
                b = new HtmlTableCell();
                c = new HtmlTableCell();
                b.BgColor = "#a9a9a9";
                c.BgColor = "#E0E9F5";
                string[] hora_fin = even.Hora_fin.ToString().Split(new char[] {' '});
                b.Controls.Add(new LiteralControl("<b>HORA FIN</b>"));
                c.Controls.Add(new LiteralControl(hora_fin[1]));
                r.Cells.Add(b);
                r.Cells.Add(c);
                eventos1.Rows.Add(r);
                r = new HtmlTableRow();
                b = new HtmlTableCell();
                c = new HtmlTableCell();
                b.BgColor = "#a9a9a9";
                c.BgColor = "#E0E9F5";

                b.Controls.Add(new LiteralControl("<b>DESCRIPCION</b>"));
                c.Controls.Add(new LiteralControl(even.Descripcion));
                r.Cells.Add(b);
                r.Cells.Add(c);
                eventos1.Rows.Add(r);
                r = new HtmlTableRow();
                b = new HtmlTableCell();
                c = new HtmlTableCell();
                b.BgColor = "#a9a9a9";
                c.BgColor = "#E0E9F5";

                b.Controls.Add(new LiteralControl("<b>NOMBRE CONTACTO</b>"));
                c.Controls.Add(new LiteralControl(even.Nombre_contacto + " " + even.Apellido_contacto));
                r.Cells.Add(b);
                r.Cells.Add(c);
                eventos1.Rows.Add(r);
            }
        }
        catch ( ConsultaException ce )
        {
            MessageBox.Show("Ha ocurrido un error, por favor intentelo mas tarde...");
            Response.Redirect("Default.aspx");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            Guia person = (Guia) Session["usuario"];
            bool flag = Control_calendario.anotarse_evento(even, person);
            if (flag)
            {
                MessageBox.Show("Se ha anotado en el evento exitosamente!!!");
                Response.Redirect("Calendario.aspx");
            }
            else
            {
                MessageBox.Show(
                    "En estos momentos el evento se encuentra lleno \n Por favor pruebe anotarse en otro evento");
                string[] a = even.Fecha.ToString().Split(new char[] {' '});
                string[] fecha2 = a[0].Split(new char[] {'/'});
                Response.Redirect("procesar_eventos.aspx?dia=" + fecha2[0] + "&mes=" + fecha2[1] + "&an=" +
                                  fecha2[2]);
            }
        }
        catch ( GuiaAnotadoException gae )
        {
            MessageBox.Show("Solo se puede anotar en un evento una sola vez.");
            string[] a = even.Fecha.ToString().Split(new char[] { ' ' });
            string[] fecha2 = a[0].Split(new char[] { '/' });
            Response.Redirect("procesar_eventos.aspx?dia=" + fecha2[0] + "&mes=" + fecha2[1] + "&an=" +
                              fecha2[2]);
        }
        catch ( ErrorException ex)
        {
            MessageBox.Show("Ha ocurrido un error, por favor intente mas tarde...");
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string[] a = even.Fecha.ToString().Split(new char[] {' '});
        string[] fecha2 = a[0].Split(new char[] {'/'});
        Response.Redirect("procesar_eventos.aspx?dia=" + fecha2[0] + "&mes=" + fecha2[1] + "&an=" +
                                  fecha2[2]);

    }
}
